CISC 1110                       Lab 2

 

Copy into your editor the loop version of program 1 that we did in class, available at this URL (or copy it from your notes):

 

http://www.sci.brooklyn.cuny.edu/~jones/cisc1110/Labs/prog1.cpp           

 

1. First, modify the program so that it does some different things, as instructed below. Run the program after each modification to see that it works.

 

a. Change the program so that it prints the even numbers from 4 to 16 together with their squares. Let the for loop header control which numbers are being processed.

 

 

b. Change the program so that it prints the numbers from 9 to 4 (in that order) together with their squares. Let the for loop header control which numbers are being processed.

                                               

 

c. Now keep the start value and the limit from part b, but use the increment from the original program. What happens? Why?    

                                                           

 

2. Now, starting with the original program each time, introduce the following errors and see if you can explain what happens in each case:

 

a. Put a semicolon after the for loop header. What happens? Can you explain why?       

           

 

                  b. Remove the semicolon you inserted in 2a. Now remove the curly braces around
                       the two statements following the loop header. What happens? Why?